using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.DataHelper;
using HoWave.Web.Shop;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Witkey_ResultWitkey : Shop, IRequiresSessionState
{
	protected Label Label_Desc;
	protected Label Label_Title;
	protected Label Label_Price;
	protected Label Label_EndDate;
	protected Label Label_xsMode;
	protected Label Label_FW;
	protected Label Label_Sum;
	protected Label Label_Balance;
	protected HtmlTable MoneyTable;
	protected Label Label_Num;
	protected Label Label_Money;
	protected Label Label_User;
	protected Label Label_Balance1;
	protected HtmlTable EndTable;
	protected LinkButton LinkButton_End;
	protected LinkButton LinkButton_OK;
	protected HyperLink HyperLink_Back;
	protected HtmlForm form1;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Init(object sender, EventArgs e)
	{
		if (!base.user.CheckUserLogin())
		{
			this.WriteErrMsg("", Language.GetMemberMsg("Common/NotLogin", new string[0]), "Passport/Login.aspx?ComeUrl=" + this.InstallDir + "SaleProduct.aspx");
		}
		try
		{
			Template.BindTemplateToPage(this.Page, "SaleProduct");
		}
		catch (Exception ex)
		{
			base.WriteTemErrMsg(ex.Message.ToString());
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			this.Initpage();
		}
	}
	protected void Initpage()
	{
		this.StringBind();
	}
	protected void StringBind()
	{
		int iD = Fetch.GetID("ww_Id");
		string text = base.Request.QueryString["Type"].ToString();
		int work_Id = 0;
		this.LinkButton_OK.Visible = false;
		this.LinkButton_End.Visible = false;
		if (base.Request.QueryString["work_Id"] != null)
		{
			work_Id = Convert.ToInt32(base.Request.QueryString["work_Id"]);
		}
		Shop_Witkey shop_Witkey = new Shop_Witkey(this.conn);
		DataTable dataTable = new DataTable();
		this.HyperLink_Back.NavigateUrl = "ShowWitkey.aspx?ww_Id=" + iD.ToString();
		string text2 = text;
		switch (text2)
		{
		case "Add":
			this.Label_Desc.Text = "<img src='img/keke/error.gif' />你已经报过名了！";
			break;
		case "As":
			this.Label_Desc.Text = "<img src='img/keke/error.gif' />不能参加自己的发布的任务！";
			break;
		case "Success":
			this.Label_Desc.Text = "<img src='img/keke/right.gif' />报名成功！";
			break;
		case "Ok_1":
			this.Label_Desc.Text = "<img src='img/keke/right.gif' />付款成功，我们会在1－2个工作日内对您的任务进行审核！";
			break;
		case "Ok_2":
			this.Label_Desc.Text = "<img src='img/keke/right.gif' />付款成功，任务圆满完成！";
			break;
		case "Error":
			this.Label_Desc.Text = "<img src='img/keke/error.gif' />操作失败！";
			break;
		case "In":
			try
			{
				shop_Witkey.UpdateWitkeyWorkStatu(work_Id, iD, 5);
				this.Label_Desc.Text = "<img src='img/keke/right.gif' />作品入围操作成功！";
			}
			catch (Exception)
			{
				this.Label_Desc.Text = "<img src='img/keke/error.gif' />作品入围操作失败！";
			}
			break;
		case "Win":
			try
			{
				shop_Witkey.UpdateWitkeyWorkStatu(work_Id, iD, 8);
				shop_Witkey.UpdateWitkeyUserInfo(base.user.UserID);
				shop_Witkey.UpdateWitkeyStatu(iD, 8);
				this.Label_Desc.Text = "<img src='img/keke/right.gif' />作品中标操作成功！";
			}
			catch (Exception)
			{
				this.Label_Desc.Text = "<img src='img/keke/error.gif' />作品中标操作失败！";
			}
			break;
		case "Money":
			try
			{
				this.LinkButton_OK.Visible = true;
				this.Label_Desc.Text = "";
				this.MoneyTable.Visible = true;
				dataTable = shop_Witkey.GetWitkey(iD);
				this.Label_Title.Text = dataTable.Rows[0]["ww_Title"].ToString();
				decimal num2 = Convert.ToDecimal(dataTable.Rows[0]["ww_xsPrice"]);
				this.ViewState["Price"] = num2;
				this.Label_Price.Text = num2.ToString();
				this.Label_Sum.Text = dataTable.Rows[0]["ww_xsPrice"].ToString();
				this.Label_xsMode.Text = dataTable.Rows[0]["ww_xsModel"].ToString();
				this.Label_FW.Text = "0元";
				this.Label_EndDate.Text = dataTable.Rows[0]["ww_EndTime"].ToString();
				this.Label_Balance.Text = base.user.Balance.ToString();
			}
			catch (Exception)
			{
				throw;
			}
			break;
		case "MoneyError":
			this.Label_Desc.Text = "<img src='img/keke/error.gif' />您的账户金额已不足，请充值后再执行！";
			break;
		case "End":
		{
			this.LinkButton_OK.Visible = true;
			this.Label_Desc.Text = "";
			this.EndTable.Visible = true;
			dataTable = shop_Witkey.GetWitkey(iD);
			DataTable witkeyWorkStatu = shop_Witkey.GetWitkeyWorkStatu(iD, 8);
			this.Label_Num.Text = witkeyWorkStatu.Rows[0]["work_Id"].ToString();
			decimal num3 = Convert.ToDecimal(dataTable.Rows[0]["ww_xsPrice"]);
			this.ViewState["Price"] = num3;
			this.ViewState["User"] = witkeyWorkStatu.Rows[0]["work_Uid"];
			this.Label_Money.Text = num3.ToString();
			this.Label_User.Text = witkeyWorkStatu.Rows[0]["UserName"].ToString();
			this.Label_Balance1.Text = base.user.Balance.ToString();
			break;
		}
		}
	}
	protected void LinkButton_OK_Click(object sender, EventArgs e)
	{
		decimal d = Convert.ToDecimal(this.ViewState["Price"]);
		if (base.user.Balance < d)
		{
			base.Response.Redirect("ResultWitkey.aspx?Type=MoneyError&&ww_Id=" + Fetch.GetID("ww_Id").ToString());
		}
		else
		{
			int iD = Fetch.GetID("ww_Id");
			UserBll userBll = new UserBll();
			Shop_Witkey shop_Witkey = new Shop_Witkey();
			shop_Witkey.UpdateWitkeyStatu(iD, 2);
			userBll.UpdateUserScope(base.user.UserID, base.user.Balance - d, base.user.UserEP);
			base.Server.Transfer("ResultWitkey.aspx?Type=Ok_1&&ww_Id=" + Fetch.GetID("ww_Id").ToString());
		}
	}
	protected void LinkButton_End_Click(object sender, EventArgs e)
	{
		decimal d = Convert.ToDecimal(this.ViewState["Price"]);
		if (base.user.Balance < d)
		{
			base.Response.Redirect("ResultWitkey.aspx?Type=MoneyError&&ww_Id=" + Fetch.GetID("ww_Id").ToString());
		}
		else
		{
			int iD = Fetch.GetID("ww_Id");
			int userID = Convert.ToInt32(this.ViewState["User"]);
			UserBll userBll = new UserBll();
			Shop_Witkey shop_Witkey = new Shop_Witkey();
			DataTable userByUserID = userBll.GetUserByUserID(userID);
			userBll.UpdateUserScope(userID, Convert.ToDecimal(userByUserID.Rows[0]["Balance"]) + d, Convert.ToInt32(userByUserID.Rows[0]["UserEP"]));
			shop_Witkey.UpdateWitkeyStatu(iD, 9);
			base.Server.Transfer("ResultWitkey.aspx?Type=Ok_2&&ww_Id=" + Fetch.GetID("ww_Id").ToString());
		}
	}
}
